<?php
namespace app\api\controller;

use app\common\model\Cate as CateModel;
use app\common\model\Forum as ForumModel;
use app\common\model\Reply as ReplyModel;

class Index extends Base
{
	public function index()
	{
		$date = date('Y-m-d');
		$clearDate = cache('clearDate');
		if($date != $clearDate){
			cache('clearDate',$date);
			CateModel::where('day_count','>',0)->update(['day_count'=>0]);
		}

		$data['carousel'] = [];
		$data['allCate'] = CateModel::select();
		$data['newForum'] = ForumModel::order('id desc')->limit(10)->select()->append(['user']);
		$data['replyForum'] = ForumModel::order('reply_time desc')->limit(10)->select()->append(['user']);
		$data['hotForum'] = ForumModel::order('hits desc')->limit(10)->select()->append(['user']);
		$data['bestForum'] = ForumModel::where(['best'=>1])->order('id desc')->limit(10)->select()->append(['user']);
		$data['picForum'] = ForumModel::where('pic','<>','')->order('id desc')->limit(10)->select()->append(['user']);
		$data['newReply'] = ReplyModel::order('id desc')->limit(10)->select()->append(['user'=>['id', 'name', 'avatar'], 'desc']);
		foreach ($data['newForum'] as $key => $value) {
			if(!empty($value['pic'])){
				array_push($data['carousel'], $value);
			}
		}
		return cdm(200, $data, '');
	}

	public function create()
	{

	}

	public function save()
	{

	}

	public function read($id)
	{

	}

	public function edit($id)
	{
		
	}

	public function update($id)
	{

	}

	public function delete($id)
	{

	}
}